package com.example.service.impl;

import com.example.dao.RestaurantMapper;
import com.example.model.OrderUser;
import com.example.dao.OrderUserMapper;
import com.example.model.Restaurant;
import com.example.modelDTO.OrderUserDTO;
import com.example.modelDTO.converter.OrderUserConverter;
import com.example.service.IOrderUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Hello
 * @since 2024-07-03
 */
@Service
public class OrderUserServiceImpl extends ServiceImpl<OrderUserMapper, OrderUser> implements IOrderUserService {

    @Autowired
    OrderUserMapper orderUserMapper;
    @Autowired
    RestaurantMapper restaurantMapper;
    /*public List<OrderUserDTO> getAll(){
        return orderUserMapper.selectList(null).stream()
                .map(OrderUserConverter::toDTO)
                .collect(Collectors.toList());

    }

    public List<OrderUserDTO> getAllDingin(){
        return orderUserMapper.getAllDingin().stream()
                .map(OrderUserConverter::toDTO)
                .collect(Collectors.toList());
    }

    public List<OrderUserDTO> getAllTakeAway(){
        return orderUserMapper.getAllTakeAway().stream()
                .map(OrderUserConverter::toDTO)
                .collect(Collectors.toList());
    }*/

    public List<OrderUserDTO> getAllById(Integer userId){
        /*List<OrderUser> orderUserList=orderUserMapper.getByUserId(userId);
        List<OrderUserDTO> orderUserDTOList=new ArrayList<>();
        for(OrderUser orderUser:orderUserList){
            orderUserDTOList.add(OrderUserConverter.toDTO(orderUser,restaurantMapper));
        }
        return orderUserDTOList;*/
        return orderUserMapper.getByUserId(userId).stream()
                .map(orderUser -> OrderUserConverter.toDTO(orderUser,restaurantMapper))
                .collect(Collectors.toList());
    }

    public List<OrderUserDTO> getAllDinginById(Integer userId){

        return orderUserMapper.getDinginByUserId(userId).stream()
                .map(orderUser -> OrderUserConverter.toDTO(orderUser,restaurantMapper))
                .collect(Collectors.toList());
    }

    public List<OrderUserDTO> getAllTakeAwayById(Integer userId){
        return orderUserMapper.getTakeAwayByUserId(userId).stream()
                .map(orderUser -> OrderUserConverter.toDTO(orderUser,restaurantMapper))
                .collect(Collectors.toList());
    }
}
